/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.pig4cloud.pig.mall.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.pig.mall.entity.CardRuleEngineer;
import com.pig4cloud.pig.mall.service.CardRuleEngineerService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;


/**
 * 规则关联工程师设置
 *
 * @author wangyl
 * @date 2023-06-05 09:10:38
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/cardruleengineer" )
@Tag(name = "规则关联工程师设置管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class CardRuleEngineerController {

    private final  CardRuleEngineerService cardRuleEngineerService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param cardRuleEngineer 规则关联工程师设置
     * @return
     */
    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('mall_cardruleengineer_get')" )
    public R getCardRuleEngineerPage(Page page, CardRuleEngineer cardRuleEngineer) {
        return R.ok(cardRuleEngineerService.page(page, Wrappers.query(cardRuleEngineer)));
    }


    /**
     * 通过id查询规则关联工程师设置
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询", description = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('mall_cardruleengineer_get')" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(cardRuleEngineerService.getById(id));
    }

    /**
     * 新增规则关联工程师设置
     * @param cardRuleEngineer 规则关联工程师设置
     * @return R
     */
    @Operation(summary = "新增规则关联工程师设置", description = "新增规则关联工程师设置")
    @SysLog("新增规则关联工程师设置" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('mall_cardruleengineer_add')" )
    public R save(@RequestBody CardRuleEngineer cardRuleEngineer) {
        return R.ok(cardRuleEngineerService.save(cardRuleEngineer));
    }

    /**
     * 修改规则关联工程师设置
     * @param cardRuleEngineer 规则关联工程师设置
     * @return R
     */
    @Operation(summary = "修改规则关联工程师设置", description = "修改规则关联工程师设置")
    @SysLog("修改规则关联工程师设置" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('mall_cardruleengineer_edit')" )
    public R updateById(@RequestBody CardRuleEngineer cardRuleEngineer) {
        return R.ok(cardRuleEngineerService.updateById(cardRuleEngineer));
    }

    /**
     * 通过id删除规则关联工程师设置
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id删除规则关联工程师设置", description = "通过id删除规则关联工程师设置")
    @SysLog("通过id删除规则关联工程师设置" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('mall_cardruleengineer_del')" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(cardRuleEngineerService.removeById(id));
    }

}
